package com.huike.clues.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.huike.clues.domain.dto.MPTbCourseDTO;
import com.huike.clues.domain.mpVO.MPTbCourseVO;
import com.huike.clues.domain.vo.MPTableDataInfoActivityListVo;
import com.huike.clues.mapper.MPCourseMapper;
import com.huike.clues.service.MPCourseService;
import com.huike.common.utils.bean.BeanUtils;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description TODO
 * @Author hxd
 * @Date 2023-08-29 21:30
 */
@Service
public class MPCourseServiceImpl extends ServiceImpl<MPCourseMapper, MPTbCourseDTO> implements MPCourseService {

    @Resource
    private MPCourseMapper mpCourseMapper;
    /**
     * 查询课程管理列表
     * @param mpTbCourseDTO
     * @return
     */
    @Override
    public MPTableDataInfoActivityListVo courseList(MPTbCourseDTO mpTbCourseDTO, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<MPTbCourseDTO> page = mpCourseMapper.courseList(mpTbCourseDTO);
//        Page page = (Page) list;

        return MPTableDataInfoActivityListVo.builder()
                .total(page.getTotal())
                .rows(page.getResult())
                .build();
    }

    /**
     * 修改课程管理
     * @param mpTbCourseDTO
     */
    @Override
    public void updateId(MPTbCourseDTO mpTbCourseDTO) {
        mpCourseMapper.updateById(mpTbCourseDTO);
    }

    /**
     * 获取课程的详细信息
     * @param id
     * @return
     */
    @Override
    public MPTbCourseDTO getId(Integer id) {
        MPTbCourseDTO mpTbCourseDTO = mpCourseMapper.selectById(id);
        return mpTbCourseDTO;
    }

    /**
     * 删除课程管理
     * @param ids
     */
    @Override
    public void deleteIds(List<Integer> ids) {
        mpCourseMapper.deleteBatchIds(ids);
    }

    /**
     * 新增课程管理
     * @param mpTbCourseDTO
     */
    @Override
    public void add(MPTbCourseDTO mpTbCourseDTO) {
        mpCourseMapper.insert(mpTbCourseDTO);
    }

    /**
     * 课程下拉列表
     * @return
     */
    @Override
    public List<MPTbCourseDTO> listselect() {
        QueryWrapper wrapper = new QueryWrapper();
        List list = mpCourseMapper.selectList(wrapper);
        return list;
    }
}
